<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Created by JetBrains PhpStorm.
 * User: b4by
 * Date: 1/23/13
 * Time: 10:18 AM
 * To change this template use File | Settings | File Templates.
 */
class ViewProduct extends MY_Controller
{
    function __construct()
    {
        parent::__construct();
		$this->load->model('model_product');
    }
	
	public function index($id)
	{
		$product = $this->model_product->get_info($id);
		
		if($product===FALSE)
		{
			show_error(lang('product_not_exist'));
		}
		
		$this->load->model('model_product_catalogue');
		$cat_ids=$this->model_product_catalogue->get_list(array(
			'where' => array('product_id'	=> $product->id),
			'order'	=> array('cat_id','RANDOM')
		));
		$this->data['catalogue'] = $this->model_catalogue->get_info($cat_ids[0]->cat_id);
		
		
		
		$this->data['site_title'] = $product->info[$this->user_lang->id]->name . ' | ' . $this->siteConfig->site_title;
//		$this->data['title'] = $product->info[$this->user_lang->id]->name;
		$this->data['product'] = $product;
		$this->data['others'] = $this->others();
		$this->data['temp'] = 'product/index';
		$this->load_view();
	}
	
	public function others()
	{
		$others = $this->model_product->get_list($this->user_lang->id,array(
			'limit'=>array(0,6),
			'order'=>array('p.id' , 'RANDOM'),
			'where'=>array('time >'=> now()-60*60*24*7)
		));
		return $others;
	}
}